package gxt.visual.selection;

import gxt.visual.util.CommonChecks;

import java.util.List;

import com.extjs.gxt.ui.client.data.BeanModelTag;
import com.extjs.gxt.ui.client.widget.MessageBox;

/**
 * @author eugenp
 */
public final class SelectionUtils{

	private SelectionUtils(){
		throw new AssertionError();
	}
	
	//
	public static final < BEAN extends BeanModelTag >boolean validateSelection( final BEAN selectedItem ){
		if( selectedItem == null ){
			MessageBox.alert( "Alert", "No item is selected", null );
			return false;
		}
		
		return true;
	}
	public static final < BEAN extends BeanModelTag >boolean validateSelection( final List< BEAN > selectedItems ){
		if( ( selectedItems == null ) || selectedItems.isEmpty() ){
			MessageBox.alert( "Alert", "No item is selected", null );
			return false;
		}
		
		return true;
	}
	
	public static final < BEAN extends BeanModelTag >boolean operationNotAllowedOnMultipleSelection( final List< BEAN > selection ){
		CommonChecks.checkNullArgs( selection );
		if( selection.size() > 1 ){
			MessageBox.alert( "Allert", "This operation cannot be performed on multiple selection. Please select a single item and try again", null );
			return false;
		}
		
		return true;
	}

}
